<template>
  <!-- 体检信息 -->
  <el-form :model="sign_form" ref="form" :rules="rules" class="basic_form">
    <el-row>
      <el-col :span="12">
        <el-form-item label="身高(CM)：" prop="height">
          <el-input class="exam_input" v-model="sign_form.height"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="体重(KG)：" prop="weight">
          <el-input class="exam_input" v-model="sign_form.weight"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="血型：">
          <el-select style="width:45%;" v-model="sign_form.bloodTypeOne">
            <el-option
              v-for="(item,index) in blood"
              :key="index"
              :value="item.id"
              :label="item.desc"
            ></el-option>
          </el-select>
          <el-select style="width:40%;margin-left:2%;" v-model="sign_form.bloodTypeTwo">
            <el-option
              v-for="(item,index) in bloodType"
              :key="index"
              :value="item.id"
              :label="item.desc"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label prop>
      <el-button type="primary" @click="onSubmit">保存</el-button>
      <el-button @click="cancel">取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import validate from "@/_js/validate";
export default {
  props: ["value", "signForm", "patientId", "blood", "bloodType"],
  data() {
    return {
      sign_form: {
        weight: "",
        height: "",
        bmi: "",
        bloodTypeOne: "",
        bloodTypeTwo: "",
        isDeleted: 0,
        patientId: "",
        temperatureType: "",
        temperature: "",
        breathing: "",
        systolicPressure: "",
        diastolicpressure: "",
        bloodsugarType: "",
        bloodsugar: "",
        leftEye: "",
        rightEye: "",
        oxygenSaturation: "",
        painScore: "",
        pulse: ""
      },
      rules: {
        height: [
          { required: true, message: "请输入身高", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 2, max: 5, message: "请输入正确的身高", trigger: "blur" }
        ],
        weight: [
          { required: true, message: "请输入体重", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 2, max: 5, message: "请输入正确的体重", trigger: "blur" }
        ]
      }
      // blood:[],
      // bloodType:[],
    };
  },
  mounted() {
    this.getBasicData();
    this.onOpen();
  },
  methods: {
    onSubmit() {
      let th = this;
      th.sign_form.patientId = th.patientId;
      if (th.sign_form.height > 10) {
        th.sign_form.bmi =
          th.sign_form.weight /
          (Number(th.sign_form.height / 100) *
            Number(th.sign_form.height / 100));
        th.sign_form.bmi = th.sign_form.bmi.toFixed(2);
      }
      th.$refs["form"].validate(v => {
        if (v) {
          th.$api.savePatientSign(th.sign_form).then(res => {
            if (res.executed) {
              th.$message.success("保存成功");
              th.$emit("success");
              th.$emit("get");
              th.$emit("input", false);
            } else {
              th.$message.error(res.message);
            }
          });
        }
      });
    },
    onOpen() {
      let th = this;
      if (th.signForm) {
        th.sign_form = Object.assign(th.sign_form, th.signForm);
        th.sign_form.status = "";
      }
    },
    getBasicData() {
      let th = this;
      // th.getCommonConfigByKey("血型").then(res => {
      //     th.blood = res;
      // });
      // th.getCommonConfigByKey("血型2").then(res => {
      //     th.bloodType = res;
      // });
    },
    cancel() {
      let th = this;
      th.$emit("input", false);
    }
  }
};
</script>
<style lang="scss" scoped>
.exam_input {
  width: 90%;
}
.basic_form {
  border-left: 1px solid #eee;
  border-right: 1px solid #eee;
  border-bottom: 1px solid #eee;
  padding: 10px;
}
</style>

